package com.example.topnewsdemo;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;

    public NewsAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        View itemView=null;
        RecyclerView.ViewHolder holder=null;
        if(viewType == 1){
            itemView = View.inflate(context,R.layout.list_item_one,null);
            holder = new MyViewHolder1(itemView);
        }else {
            itemView = View.inflate(context,R.layout.list_item_two,null);
            holder = new MyViewHolder2(itemView);
        }
            
        return  holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {

    }

    @Override
    public int getItemCount() {
        return 0;
    }
    // 一个图片
    class MyViewHolder1 extends RecyclerView.ViewHolder{
        ImageView iv_top,iv_img;
        TextView title, name,comment,time;

        public MyViewHolder1(@NonNull View itemView) {
            super(itemView);
            iv_top = itemView.findViewById(R.id.iv_top);
            iv_img = itemView.findViewById(R.id.iv_img);
            title = itemView.findViewById(R.id.tv_title);
            name = itemView.findViewById(R.id.tv_name);
            comment = itemView.findViewById(R.id.tv_comment);
            time = itemView.findViewById(R.id.tv_time);
        }
    }
    // 三个图片
    class MyViewHolder2 extends  RecyclerView.ViewHolder{
        ImageView iv_img1,iv_img2,iv_img3;
        TextView title, name,comment,time;

        public MyViewHolder2(@NonNull View itemView) {
            super(itemView);
            iv_img1 = itemView.findViewById(R.id.iv_img1);
            iv_img2 = itemView.findViewById(R.id.iv_img2);
            iv_img3 = itemView.findViewById(R.id.iv_img3);
            title = itemView.findViewById(R.id.tv_title);
            name = itemView.findViewById(R.id.tv_name);
            comment = itemView.findViewById(R.id.tv_comment);
            time = itemView.findViewById(R.id.tv_time);
        }
    }
}
